import axios from "axios";
import API from '@/api/cjy-api'
import {Toast} from '../../utils/toast'
export default {
    namespaced: true,
    state: {
        payForOthersOrderMsg: {},             //代付订单信息
        payForOthersPayMsg: {},               //代付支付信息
        //payForOthersStatus: false             //获取的订单信息是否失效
        payForOthersStatus: 0                 //0: 正常订单，1：订单过期或系统错误未找到订单，2.订单已完成
    },
    getters: {
        getPageMsg: (state) => {
            return state.payForOthersOrderMsg
        },
        getPFOPayMsg:(state) => {
            return state.payForOthersPayMsg
        }
    },
    actions: {
        getPFOOrderMsg({commit},param) {
            let self = this
            axios({
                url: API().pfoOrderMsg,
                headers: {
                    "sessionId":localStorage.getItem('sessionId'),
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                data: {"param":param},
                method: "POST",
                transformRequest: [function (data) {
                let ret = ''
                for (let it in data) {
                    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                }
                return ret
                }],
            }).then(function(res) {
                commit('SET_ORDER_STATUS', res.data.returnCode)
                commit('GET_PFOOMSG', res.data.data[0])
            }).catch(function(e) {
                // Toast({
                //     duration: 1000,
                //     type: 'fail',
                //     message: '获取代付信息失败'
                // })
            })
            
        },
    
    },
    mutations: {
        GET_PFOOMSG(state, res) {
            res = res ? res : {}
            state.payForOthersOrderMsg = res
        },
        SET_ORDER_STATUS(state, code) {
            switch (code) {
                case 0:
                    state.payForOthersStatus = 1
                    break;
                case 2:
                    state.payForOthersStatus = 2
                    break;
                default:
                    state.payForOthersStatus = 0
                    break;
            }
        }
    }
}